package yuanzhui;

	public class wugui extends Thread {
		   int waterAmount;       //用int变量模拟水量
		   public void setWater(int w) {
		      waterAmount = w;
		   }
		   public void run() {     
		      while(true) {
		         String name=Thread.currentThread().getName();
		         if(name.equals("乌龟")) { 
		              System.out.println(name+"跑了两米") ; 
		              int n=(int)(Math.random()*2+1);
		              waterAmount=waterAmount-2;  
		              System.out.println("乌龟休息"+n+"s") ;
		         }
		       
		         System.out.println(" 乌龟剩 "+waterAmount);
		         
		        try{  Thread.sleep(1000);  //间隔时间
		        
		        }
		         catch(InterruptedException e){}  
		         if(waterAmount<=0) {
		        	 System.out.println("乌龟到达终点") ;
		                 return;    
		         }  

}
		   }
	}
